package main;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.ZipLocator;
import com.jme3.font.BitmapText;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.system.AppSettings;
import com.jme3.util.TangentBinormalGenerator;
import model.Ninja;

/**
 * test
 * @author normenhansen
 */
public class Main extends SimpleApplication {
    Geometry shiny_rock;
    private static Main app;
    public static void main(String[] args) {
        AppSettings settings = new AppSettings(true);
          settings.setResolution(640,480);
          settings.setBitsPerPixel(24);
          
          app = new Main();
          app.setSettings(settings);
          app.setShowSettings(false);
          app.start();
          
    }

    @Override
    public void simpleInitApp() {
        ninjaTown();
        model.Ninja ninja = new model.Ninja();
        new Controller(inputManager, this.app, speed);
        
       
 
    }
    
    private void ninjaTown(){
        
        Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
        Material mat_default = new Material( 
            assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        teapot.setMaterial(mat_default);
        rootNode.attachChild(teapot);
 
        // Create a wall with a simple texture from test_data
        Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);
         TangentBinormalGenerator.generate(box); 
        Spatial wall = new Geometry("Box", box );
        Material mat_brick = new Material( 
            assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat_brick.setTexture("DiffuseMap", 
            assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
        mat_brick.setTexture("NormalMap", 
            assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall_normal.jpg"));
        mat_brick.setBoolean("UseMaterialColors",true);    
        mat_brick.setColor("Specular",ColorRGBA.Black);
        mat_brick.setColor("Diffuse",ColorRGBA.White);
        mat_brick.setColor("Ambient",ColorRGBA.DarkGray);
        mat_brick.setFloat("Shininess", 4f); // [1,128]    
        wall.setMaterial(mat_brick);
        wall.setLocalTranslation(2.0f,-2.5f,0.0f);
        rootNode.attachChild(wall);
 
        // Display a line of text with a default font
        guiNode.detachAllChildren();
        guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
        BitmapText helloText = new BitmapText(guiFont, false);
        helloText.setSize(guiFont.getCharSet().getRenderedSize());
        helloText.setText("Hello World");
        helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
        guiNode.attachChild(helloText);
 
        /** A bumpy rock with a shiny light effect */
        Sphere rock = new Sphere(32,32, 2f);
        shiny_rock = new Geometry("Shiny rock", rock);
        TangentBinormalGenerator.generate(rock);           // for lighting effect
        rock.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
        Material mat_lit = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat_lit.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
        mat_lit.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
        mat_lit.setBoolean("UseMaterialColors",true);    
        mat_lit.setColor("Specular",ColorRGBA.White);
        mat_lit.setColor("Diffuse",ColorRGBA.White);
        mat_lit.setFloat("Shininess", 100f); // [1,128]    
        shiny_rock.setMaterial(mat_lit);
        shiny_rock.setLocalTranslation(3f,1.95f,0f); // Move it a bit
        shiny_rock.rotate(FastMath.HALF_PI, 0, 0);          // Rotate it a bit
        rootNode.attachChild(shiny_rock);
       
        // You must add a light to make the model visible
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
        rootNode.addLight(sun);
        
        Spatial gameLevel = assetManager.loadModel("Scenes/town/main.j3o");
        gameLevel.setLocalTranslation(0, -5.2f, 0);
        gameLevel.setLocalScale(2);
        rootNode.attachChild(gameLevel);
        
        AmbientLight al=new AmbientLight();
        al.setColor(new ColorRGBA(1.8f,1.8f,1.8f,1.0f));
        rootNode.addLight(al);
        
        flyCam.setMoveSpeed(10f);        
    }
    
     @Override
    public void simpleUpdate(float tpf) {
        // make the player rotate
        this.shiny_rock.rotate(0f, 0f, tpf*0.5f); 
    }
    
}
